package com.scholarship.modules.backend.controller;

import com.scholarship.common.entity.RetCode;
import com.scholarship.common.entity.RetResponse;
import com.scholarship.common.entity.RetResult;
import com.scholarship.modules.backend.entity.RewardType;
import com.scholarship.modules.backend.service.RewardTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhz
 * @date 2021/4/24 20:30
 * 备注：关于奖学金类型表的一系列数据库操作
 */
@Api(tags = {"奖学金类型表的增删改查"})
@RestController
public class RewardTypeController {

    @Autowired
    RewardTypeService rewardTypeService;

    @ApiOperation("获取所有奖学金类型 @author zhz")
    @GetMapping("/admin/ListRewardType")
    public RetResult ListRewardType(){
        List<RewardType> list = rewardTypeService.listRewardType();
        return RetResponse.makeRsp(RetCode.SUCCESS,"成功展现所有的奖学金类型",list);
    }

    @ApiOperation("添加奖学金类型 @author zhz")
    @PostMapping("/admin/addRewardType")
    public RetResult addRewardType(@RequestBody RewardType rewardType){
        return RetResponse.makeRsp(RetCode.SUCCESS,"增加了"+rewardTypeService.addRewardType(rewardType)+"行");
    }

    @ApiOperation("更改奖学金类型 @author zhz")
    @PostMapping("/admin/updateRewardType")
    public RetResult updateRewardType(@RequestBody RewardType rewardType){
        Integer result = rewardTypeService.updateRewardType(rewardType);
        if(result==-1){
            return RetResponse.makeRsp(RetCode.FAIL,"id不存在");
        }else{
            return RetResponse.makeRsp(RetCode.SUCCESS,"修改了"+result+"行");
        }
    }

    @ApiOperation("删除奖学金类型 @author zhz")
    @PostMapping("/admin/deleteRewardType")
    public RetResult deleteRewardType(@RequestBody RewardType rewardType){
        Integer result = rewardTypeService.deleteRewardType(rewardType);
        if(result==-1){
            return RetResponse.makeRsp(RetCode.FAIL,"id不存在");
        }else{
            return RetResponse.makeRsp(RetCode.SUCCESS,"删除了"+result+"行");
        }
    }
}
